home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / VPOJAVA.DLL / SOURCE / SIMPLEAPP < prev    next >
Text File  |  1998-12-10  |  8KB  |  268 lines

  1. /*
  2.     This simple extension of the java.awt.Frame class
  3.     contains all the elements necessary to act as the
  4.     main window of an application.
  5.  */
  6.  
  7. import java.awt.*;
  8.  
  9. public class Frame1 extends Frame
  10. {
  11.     public Frame1()
  12.     {
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.         
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setSize(405,305);
  22.         setVisible(false);
  23.         openFileDialog1.setMode(FileDialog.LOAD);
  24.         openFileDialog1.setTitle("Open");
  25.         //$$ openFileDialog1.move(24,312);
  26.         setTitle("AWT Application");
  27.         //}}
  28.         
  29.         //{{INIT_MENUS
  30.         menu1.setLabel("File");
  31.         menu1.add(newMenuItem);
  32.         newMenuItem.setEnabled(false);
  33.         newMenuItem.setLabel("New");
  34.         newMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_N,false));
  35.         menu1.add(openMenuItem);
  36.         openMenuItem.setLabel("Open...");
  37.         openMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_O,false));
  38.         menu1.add(saveMenuItem);
  39.         saveMenuItem.setEnabled(false);
  40.         saveMenuItem.setLabel("Save");
  41.         saveMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_S,false));
  42.         menu1.add(saveAsMenuItem);
  43.         saveAsMenuItem.setEnabled(false);
  44.         saveAsMenuItem.setLabel("Save As...");
  45.         menu1.add(separatorMenuItem);
  46.         menu1.add(exitMenuItem);
  47.         exitMenuItem.setLabel("Exit");
  48.         mainMenuBar.add(menu1);
  49.         menu2.setLabel("Edit");
  50.         menu2.add(cutMenuItem);
  51.         cutMenuItem.setEnabled(false);
  52.         cutMenuItem.setLabel("Cut");
  53.         cutMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_X,false));
  54.         menu2.add(copyMenuItem);
  55.         copyMenuItem.setEnabled(false);
  56.         copyMenuItem.setLabel("Copy");
  57.         copyMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_C,false));
  58.         menu2.add(pasteMenuItem);
  59.         pasteMenuItem.setEnabled(false);
  60.         pasteMenuItem.setLabel("Paste");
  61.         pasteMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_V,false));
  62.         mainMenuBar.add(menu2);
  63.         menu3.setLabel("Help");
  64.         menu3.add(aboutMenuItem);
  65.         aboutMenuItem.setLabel("About...");
  66.         mainMenuBar.add(menu3);
  67.         //$$ mainMenuBar.move(0,312);
  68.         setMenuBar(mainMenuBar);
  69.         //}}
  70.         
  71.         //{{REGISTER_LISTENERS
  72.         SymWindow aSymWindow = new SymWindow();
  73.         this.addWindowListener(aSymWindow);
  74.         SymAction lSymAction = new SymAction();
  75.         openMenuItem.addActionListener(lSymAction);
  76.         exitMenuItem.addActionListener(lSymAction);
  77.         aboutMenuItem.addActionListener(lSymAction);
  78.         //}}
  79.     }
  80.     
  81.     public Frame1(String title)
  82.     {
  83.         this();
  84.         setTitle(title);
  85.     }
  86.     
  87.     /**
  88.      * Shows or hides the component depending on the boolean flag b.
  89.      * @param b  if true, show the component; otherwise, hide the component.
  90.      * @see java.awt.Component#isVisible
  91.      */
  92.     public void setVisible(boolean b)
  93.     {
  94.         if(b)
  95.         {
  96.             setLocation(50, 50);
  97.         }    
  98.         super.setVisible(b);
  99.     }
  100.     
  101.     static public void main(String args[])
  102.     {
  103.         try
  104.         {
  105.             //Create a new instance of our application's frame, and make it visible.
  106.             (new Frame1()).setVisible(true);
  107.         }
  108.         catch (Throwable t)
  109.         {
  110.             System.err.println(t);
  111.             t.printStackTrace();
  112.             //Ensure the application exits with an error condition.
  113.             System.exit(1);
  114.         }
  115.     }
  116.     
  117.     public void addNotify()
  118.     {
  119.         // Record the size of the window prior to calling parents addNotify.
  120.         Dimension d = getSize();
  121.         
  122.         super.addNotify();
  123.     
  124.         if (fComponentsAdjusted)
  125.             return;
  126.     
  127.         // Adjust components according to the insets
  128.         setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
  129.         Component components[] = getComponents();
  130.         for (int i = 0; i < components.length; i++)
  131.         {
  132.             Point p = components[i].getLocation();
  133.             p.translate(getInsets().left, getInsets().top);
  134.             components[i].setLocation(p);
  135.         }
  136.         fComponentsAdjusted = true;
  137.     }
  138.     
  139.     // Used for addNotify check.
  140.     boolean fComponentsAdjusted = false;
  141.     
  142.     //{{DECLARE_CONTROLS
  143.     java.awt.FileDialog openFileDialog1 = new java.awt.FileDialog(this);
  144.     //}}
  145.     
  146.     //{{DECLARE_MENUS
  147.     java.awt.MenuBar mainMenuBar = new java.awt.MenuBar();
  148.     java.awt.Menu menu1 = new java.awt.Menu();
  149.     java.awt.MenuItem newMenuItem = new java.awt.MenuItem();
  150.     java.awt.MenuItem openMenuItem = new java.awt.MenuItem();
  151.     java.awt.MenuItem saveMenuItem = new java.awt.MenuItem();
  152.     java.awt.MenuItem saveAsMenuItem = new java.awt.MenuItem();
  153.     java.awt.MenuItem separatorMenuItem = new java.awt.MenuItem("-");
  154.     java.awt.MenuItem exitMenuItem = new java.awt.MenuItem();
  155.     java.awt.Menu menu2 = new java.awt.Menu();
  156.     java.awt.MenuItem cutMenuItem = new java.awt.MenuItem();
  157.     java.awt.MenuItem copyMenuItem = new java.awt.MenuItem();
  158.     java.awt.MenuItem pasteMenuItem = new java.awt.MenuItem();
  159.     java.awt.Menu menu3 = new java.awt.Menu();
  160.     java.awt.MenuItem aboutMenuItem = new java.awt.MenuItem();
  161.     //}}
  162.     
  163.     class SymWindow extends java.awt.event.WindowAdapter
  164.     {
  165.         public void windowClosing(java.awt.event.WindowEvent event)
  166.         {
  167.             Object object = event.getSource();
  168.             if (object == Frame1.this)
  169.                 Frame1_WindowClosing(event);
  170.         }
  171.     }
  172.     
  173.     void Frame1_WindowClosing(java.awt.event.WindowEvent event)
  174.     {
  175.         // to do: code goes here.
  176.              
  177.         Frame1_WindowClosing_Interaction1(event);
  178.     }
  179.  
  180.  
  181.     void Frame1_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
  182.     {
  183.         try {
  184.             // QuitDialog Create and show as modal
  185.             (new QuitDialog(this, true)).setVisible(true);
  186.         } catch (Exception e) {
  187.         }
  188.     }
  189.  
  190.     
  191.     class SymAction implements java.awt.event.ActionListener
  192.     {
  193.         public void actionPerformed(java.awt.event.ActionEvent event)
  194.         {
  195.             Object object = event.getSource();
  196.             if (object == openMenuItem)
  197.                 openMenuItem_ActionPerformed(event);
  198.             else if (object == aboutMenuItem)
  199.                 aboutMenuItem_ActionPerformed(event);
  200.             else if (object == exitMenuItem)
  201.                 exitMenuItem_ActionPerformed(event);
  202.         }
  203.     }
  204.     
  205.     void openMenuItem_ActionPerformed(java.awt.event.ActionEvent event)
  206.     {
  207.         // to do: code goes here.
  208.              
  209.         openMenuItem_ActionPerformed_Interaction1(event);
  210.     }
  211.  
  212.  
  213.     void openMenuItem_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  214.     {
  215.         try {
  216.             // OpenFileDialog Create and show as modal
  217.             int        defMode         = openFileDialog1.getMode();
  218.             String    defTitle        = openFileDialog1.getTitle();
  219.             String defDirectory     = openFileDialog1.getDirectory();
  220.             String defFile          = openFileDialog1.getFile();
  221.  
  222.             openFileDialog1 = new java.awt.FileDialog(this, defTitle, defMode);
  223.             openFileDialog1.setDirectory(defDirectory);
  224.             openFileDialog1.setFile(defFile);
  225.             openFileDialog1.setVisible(true);
  226.         } catch (Exception e) {
  227.         }
  228.     }
  229.  
  230.  
  231.     void aboutMenuItem_ActionPerformed(java.awt.event.ActionEvent event)
  232.     {
  233.         // to do: code goes here.
  234.              
  235.         aboutMenuItem_ActionPerformed_Interaction1(event);
  236.     }
  237.  
  238.  
  239.     void aboutMenuItem_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  240.     {
  241.         try {
  242.             // AboutDialog Create and show as modal
  243.             (new AboutDialog(this, true)).setVisible(true);
  244.         } catch (Exception e) {
  245.         }
  246.     }
  247.     
  248.     
  249.     void exitMenuItem_ActionPerformed(java.awt.event.ActionEvent event)
  250.     {
  251.         // to do: code goes here.
  252.              
  253.         exitMenuItem_ActionPerformed_Interaction1(event);
  254.     }
  255.  
  256.  
  257.     void exitMenuItem_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  258.     {
  259.         try {
  260.             // QuitDialog Create and show as modal
  261.             (new QuitDialog(this, true)).setVisible(true);
  262.         } catch (Exception e) {
  263.         }
  264.     }
  265.  
  266. }
  267.  
  268.